package com.lzw.controller;

import com.lzw.bean.Provider;
import com.lzw.service.ProviderService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;


@RestController
@RequestMapping("/provider")
public class ProviderController {

    @Autowired
    private ProviderService providerService;


    /**
     * 获取下拉框数据
     * @return
     */
    @GetMapping("/selectList")
    public  void getProviderSelectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<Provider> providerList = providerService.getProviderSelectList();
        //把providerList转换成json对象输出
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        PrintWriter outPrintWriter = response.getWriter();
        outPrintWriter.write(JSON.toJSONString(providerList));
        outPrintWriter.flush();
        outPrintWriter.close();
//        return providerList;
    }





    @GetMapping("/add")
    public ModelAndView addBillPage(ModelAndView modelAndView){
        modelAndView.setViewName("/jsp/billadd");
        return modelAndView;
    }



}
